<?php

use Illuminate\Support\Facades\Route;

use Smbear\Payment\Facades\PaymentFacades;

use Smbear\Payment\Services\PaymentConfig;

use Illuminate\Support\Facades\Gate;

use Smbear\Paypal\Facades\PaypalFacades;

use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Smbear\Paypal\Services\PaypalConfigService;
use App\Contracts\FileInterface;
use App\Services\DemoService;
use Smbear\AvaTax\Facades\AvaTaxFacades;
use Smbear\AvaTax\Services\AvaTaxClientService;
use Smbear\AvaTax\Contracts\AvaTaxInterface;


Route::get('avatax',function (\Illuminate\Http\Request $request,AvaTaxInterface $service){

    //验证地址

    $result = AvaTaxFacades::setTransportAddress([
        'line1' => '380 Centerpoint Blvd ',
        'city' => 'New Castle',
        'country' => 'US',
        'postalCode' => '19720',
        'region' => 'DE'
    ])->setOrder([
        'documentCode'     => 'FS210518112407',
        'customerCode'     => 5712928316,
        'entityUseCode'    => 5712922816,
        'currencyCode'     => 'USD',
        'exchangeRate'     => 1,
        'description'      => 'delay',
        'purchaseOrderNo'  => 'FS210518112407',
        'salespersonCode'  => 3414,
        'lines'            =>[
            [
                'amount'=> 8000,
                'quantity'=>3,
                'itemCode'=>'FR020100',
                'taxCode' =>'Shipping',
                'lineNumber' =>1,
                'description' => '发微服务全额付'
            ],
            [
                'amount'=>800,
                'quantity'=>3,
                'itemCode'=>'30775:449cacd32bbd30eeffde5f44e2f1d150',
                'taxCode' =>'Shipping',
                'lineNumber' =>3,
                'description' => '发微服务全额付'
            ],
        ],
        'adjustmentReason' => '全额负担全微分'
    ])
        ->createTransaction('SalesOrder');

    dd($result);

});




/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('container','App\Http\Controllers\Controller@ddd');


Route::get('pay/callback/paypal',function (\Illuminate\Http\Request $request){

    $data = PaypalFacades::getOrder($request->input('token'));

    if ($data['status'] == 'success'){
        dd($data['message']);
    }

    dd($data['message']);
});

Route::get('pay/callback/cancel',function (\Illuminate\Http\Request $request){

    dd('取消支付');
});

Route::get('/paypal',function (\Illuminate\Http\Request $request){
    $data = PaypalFacades::setAmount(258,'USD')
        ->setReferenceId('FS000000001')
        ->createOrder();

    if ($data['status'] == 'success'){
        $data = $data['data'];

        dd($data);

        return redirect($data->links[1]->href);
    }
});



Route::get('/paypal/info',function (\Illuminate\Http\Request $request){
    dd(1111);
});

Route::get('gates',function (\Illuminate\Http\Request $request){
    $user = App\Models\Users::find(1);

    if (Gate::forUser($user)->allows('delete-user', $request)) {
        dd('用户可以操作');
    }

    if (Gate::forUser($user)->denies('delete-user', $request)) {
        dd('用户不能操作');
    }
});

Route::get('show',function (){
   $paymentConfig = new PaymentConfig();

   dd($paymentConfig->getConfigValue('admin'));
});


Route::get('/payment',function (\Illuminate\Http\Request $request){
    return PaymentFacades::setLocalLanguage('en')
        ->getHostedCheckoutStatus($request->input('hostedCheckoutId'),$request->input('RETURNMAC'));
});

Route::get('/', function () {

    $Amount = 2100;
    $CurrencyCode = 'USD';
    $CountryCode = 'US';
    $city = 'Amsterdam';


    $params = PaymentFacades::setAddress([
        'countryCode' => $CountryCode,
        'city'        => $city,
        'street'      => '002700 Spring Cypress Rd',
        'zip'         => '98057'
    ])
        ->setContactDetails([
            'email' => 'ywjmylove@163.com'
        ])
        ->setCompanyInformation([
            'company' => 'feisu'
        ])
        ->setAmountOfMoney([
            'amount'       => $Amount,
            'currencyCode' => $CurrencyCode
        ])
        ->setPersonalName([
            'firstName' => 'Smile',
            'lastName'  => 'Yi'
        ])
        ->setAddressPersonal([
            'city'        => $city,
            'countryCode' => $CountryCode,
            'zip'         => '20016'
        ])
        ->setOrderReferences([
            'merchantReference' => 'FS210429002473-195148',
            'merchantOrderId'   => '2020113615'
        ])
        ->setHostedCheckoutSpecificInput([
            'locale' => 'en_GB',
            'payment_method' => [
                1
            ]
        ])
        ->createHostedCheckoutRequest(1);

    return redirect($params['partialRedirectUrl']);

});

Route::get('/demo',function (){
    return view('welcome');
});
